package com.huawang.mdesign.model.service.util;

import com.huawang.business.vo.CheckValidPropertyValueVo;
import com.huawang.core.definition.mof.cmof.reflection.impl.BasicRElement;
import com.huawang.core.definition.mof.instances.MetaClassInstance;
import org.apache.commons.collections4.CollectionUtils;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class CheckValidPropertyValueUtils {

    private CheckValidPropertyValueUtils() {

    }
    /**
     * 根据指定的模型，过滤出可用的id
     *
     */
    @NotNull
    public static List<CheckValidPropertyValueVo> getCheckValidPropertyValueByCheckedInstances(List<MetaClassInstance> checkedInstances, List<String> ids) {
        if (CollectionUtils.isEmpty(checkedInstances) || CollectionUtils.isEmpty(ids)) {
            return Collections.emptyList();
        }
        Set<String> checkedInstanceIdList =
                checkedInstances.stream().map(BasicRElement::getId).collect(Collectors.toSet());

        return ids.stream().map(id -> {
            CheckValidPropertyValueVo vo = new CheckValidPropertyValueVo();
            vo.setId(id);
            if (checkedInstanceIdList.contains(id)) {
                vo.setSelectable(true);
            }
            return vo;
        }).collect(Collectors.toList());
    }
}
